package main

import (
	"fmt"
	"os"
	"pan/config"
	"pan/mq"

	dbproxy "pan/service/dbproxy/client"
	cfg "pan/service/upload/config"
	upProto "pan/service/upload/proto"
	"pan/service/upload/route"
	upRpc "pan/service/upload/rpc"

	"go-micro.dev/v4"
)

// 开启rpc服务
func startRPCService() {
	service := micro.NewService(
		micro.Name("upload"), // 服务名称
	)
	service.Init()
	// 初始化dbproxy client
	dbproxy.Init(service)
	// 初始化mq client
	mq.Init()

	upProto.RegisterUploadServiceHandler(service.Server(), new(upRpc.Upload))
	if err := service.Run(); err != nil {
		fmt.Println(err)
	}
}

// startAPIService 开启api服务
func startAPIService() {
	router := route.Router()
	router.Run(cfg.UploadServiceHost)
}

func main() {
	os.MkdirAll(config.TempLocalRootDir, 0777)
	os.MkdirAll(config.TempPartRootDir, 0777)
	// api 服务
	go startAPIService()
	// rpc 服务
	startRPCService()
}
